package com.health.controller.checkItem;

import com.alibaba.dubbo.config.annotation.Reference;
import com.health.constant.MessageConstant;
import com.health.entity.PageResult;
import com.health.entity.QueryPageBean;
import com.health.entity.Result;
import com.health.pojo.CheckItem;
import com.health.service.CheckItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Classname CheckItemController
 * @Description TODO
 * @Version 1.0.0
 * @Date 2023/3/15 13:41
 * @Author RainGrd
 */
@RestController
@RequestMapping("/checkItem")
@Slf4j
public class CheckItemController {

    @Reference
    private CheckItemService checkItemService;

    /**
     * 用于保存预约管理
     *
     * @param checkItem
     * @return
     */
    @PreAuthorize("hasAuthority('CHECKITEM_ADD')")//权限校验
    @RequestMapping("/add.do")
    public Result add(@RequestBody CheckItem checkItem) {
        log.info("checkItem:{}", checkItem);
        try {
            int i = checkItemService.saveCheckItem(checkItem);
            return i > 0 ? Result.success(MessageConstant.ADD_CHECKITEM_SUCCESS) : Result.error(MessageConstant.ADD_CHECKITEM_FAIL);
        } catch (Exception e) {
            return Result.error(MessageConstant.ADD_CHECKITEM_FAIL);
        }
    }

    /**
     * 用于查询全部预约管理
     *
     * @return
     */
    @RequestMapping("/queryAll.do")
    public Result queryAll() {
        log.info(checkItemService.queryAll().toString());
        return Result.success(checkItemService.queryAll());
    }

    /**
     * 分页查询预约管理
     *
     * @param queryPageBean
     * @return
     */
    //权限校验
    @PreAuthorize("hasAuthority('CHECKITEM_QUERY')")
    @RequestMapping("/findPage.do")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {
        log.info("queryPageBean:{}", queryPageBean);
        return checkItemService.queryCheckItemPage(queryPageBean);
    }

    /**
     * 根据id删除预约管理
     *
     * @param id
     * @return
     */
    @PreAuthorize("hasAuthority('CHECKITEM_DELETE')")//权限校验
    @RequestMapping("/delete.do")
    public Result delete(@RequestParam Long id) {
        log.info("要删除的预约管理id:{}", id);
        return checkItemService.clearCheckItem(id);
    }

    /**
     * 编辑
     * @param checkItem
     * @return
     */
    @PreAuthorize("hasAuthority('CHECKITEM_EDIT')")//权限校验
    @RequestMapping("/edit.do")
    public Result edit(@RequestBody CheckItem checkItem) {
        log.info("要编辑的预约管理:{}", checkItem);
        return checkItemService.editCheckItem(checkItem);
    }

}
